# coding:utf-8
import ConfigParser
import sys
import client

class Nvm(ConfigParser.ConfigParser, object):
    def __init__(self, path):
        super(Nvm, self).__init__()
        self.path = path
        self.read(path)

    def reset(self, section='result'):
        key_list = self.options(section)
        for k in key_list:
            self.set(section, k, 0)
        f = open(self.path, 'w')
        self.write(f)
        f.close()

    def getv(self, key, section='result'):
        value = self.get(section, key)
        return value

    def setv(self, key, value, section='result'):
        value = str(value)
        self.set(section, key, value)
        f = open(self.path, 'w')
        self.write(f)
        f.close()

    def addv(self, key, value, section='result'):
        nvm_value = self.getv(key, section)
        value_num = int(nvm_value) + value
        self.setv(key, value_num, section)


if __name__ == '__main__':
    # print 'start reset result.ini'
    cf = Nvm('result.ini')  # 加载配置文件
    cf.reset('result')
    client.req('new')

'''
#使用介绍
cf=Nvm('result.ini') #加载配置文件 
value = cf.getv('ppp_test_time')   #读取某个域下的key值
value = int(value)
cf.reset()
if value == 1000:   #读取出来的是字符串类型
    print 'ok'
value = cf.getv('ppp_test_time') 
value = cf.getv('ppp_test_time') 
cf.setv('ppp_test_time','100')
print cf.getv('ppp_test_time') 
for k in cf.options('result'):   #获取某个域下的所有key
    print k
#cf.reset('test')    重置某个域下所有key的value为0
'''
